package com.feng.rabbitmq.six;

import com.feng.rabbitmq.utiils.RabbitMQUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

/**
 * 消费者接收消息
 * 2021-12-10 09:54
 */
public class ReceiveLogsDirect02 {
    public static final String EXCHANGE_NAME = "direct_logs";
    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMQUtils.getChannel();
        //声明一个交换机
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
        //声明一个队列
        channel.queueDeclare("disk",false,false,false,null);
        //交换机和队列绑定
        channel.queueBind("disk",EXCHANGE_NAME,"error");

        //接收消息
        DeliverCallback deliverCallback = (consumerTag,message) -> {
            System.out.println("ReceiveLogsDirect02控制台打印接收到的消息："+new String(message.getBody(),"utf-8"));
        };
        channel.basicConsume("disk",true,deliverCallback,consumerTag -> {
            System.out.println("消费者取消消息时回调");
        });
    }
}
